'use strict';

const express = require('express');
const router = express.Router();

const multer = require('multer');
// 定义上传的目录
const upload = multer({ dest: 'uploads/' });

const controller = require('./controller.js');

// 微信登录
router.post('/api/mplogin', controller.mplogin);

router.post('/api/upload', upload.single('avatar'), controller.upload);

router.get('/api/getlunbo', controller.getlunbo);

router.get('/api/kuaidi', controller.kuaidi);

router.get('/api/recommend', controller.recommend);

router.get('/api/getnewslist', controller.getnewslist);

router.get('/api/getnew/:news_id', controller.getnew);

router.get('/api/getthumbimages/:id', controller.getthumbimages);

router.get('/api/getcomments/:news_id', controller.getcomments);

router.post('/api/postcomment/:news_id', controller.postcomment);

// 商品列表
router.get('/api/getListgoods', controller.getListgoods);

router.get('/api/getgoodsinfo/:id', controller.getgoodsinfo);

router.get('/api/getshopcarlist/:ids', controller.getshopcarlist);

// 商品搜索接口
router.get('/api/search', controller.search);

// 登录
router.post('/api/login', controller.login);

// 注册
router.post('/api/register', controller.register);

// 获取用户收货地址
router.get('/api/getaddress/', controller.getaddress);

// 用户添加收货地址
router.post('/api/addaddress/', controller.addaddress);

// 用户删除收货地址
router.post('/api/deladdress', controller.deladdress);

// 用户编辑收货地址
router.post('/api/updateaddress', controller.updateaddress);

// 提交订单
router.post('/api/commitorder', controller.commitorder);

// 获取个人订单
router.post('/api/userorder', controller.userorder);

// 查询某个订单
router.post('/api/getorder', controller.getorder);

// 获取扫码支付链接
router.post('/api/payqrcode', controller.payqrcode);

// 查询微信支付订单状态
router.post('/api/queryPayOrder', controller.queryPayOrder);

// 小程序支付结异步通知
router.post('/api/mpnotify', controller.mpnotify);

// 扫码支付结果异步通知
router.post('/api/qrcodenotify', controller.qrcodenotify);

// 刷新token
router.post('/api/refreshToken', controller.refreshToken);

// 获取分类数据
router.get('/api/getcategory', controller.getcategory);

// 获取指定分类下面商品
router.get('/api/getcategorygoods', controller.getcategorygoods);

// 取消订单
router.post('/api/cancelorder', controller.cancelorder);

// 删除订单
router.post('/api/delorder', controller.delorder);

// 获取历史浏览
router.get('/api/history', controller.history);

// 添加历史浏览
router.post('/api/addhistory', controller.addhistory);

// 修改密码
router.post('/api/updatepassword', controller.updatePassword);

router.get('/api/test/', (req, res) => {
  res.json({ title: process.env.BASE_TITLE, message: 'hello' });
});

router.all('*', (req, res) => {
  res.json({ info: '请检查接口地址是否有误联系管理员' });
});

module.exports = router;
